﻿Imports Negocio
Imports Servicios
Imports Excepciones

Public Class frmCambioIdioma

    Protected Overrides Sub PreLoad()
        Me.Icon = Icon.FromHandle(Global.SIPRO.My.Resources.Resources.locale.GetHicon())
    End Sub

    Private Sub frmCambioIdioma_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Init()
    End Sub

    Private Sub Init()
        Try
            Dim idis As List(Of Idioma) = GesIdiomas.Consultar(Nothing)
            cbIdiomas.DataSource = idis
            cbIdiomas.ValueMember = "OID"
            cbIdiomas.DisplayMember = "Nombre"
        Catch ex As Exception
            My.Application.HandlerException(ex)
            Me.Close()
        End Try
    End Sub

    Private Sub btnCancel_Click(sender As System.Object, e As System.EventArgs) Handles btnCancelar.Click
        Me.Close()
    End Sub

    Private Sub btnAceptar_Click(sender As System.Object, e As System.EventArgs) Handles btnAceptar.Click
        MyBase.ResetErrorUI(cbIdiomas)
        If TypeOf cbIdiomas.SelectedItem Is Idioma Then
            Dim idi As New Idioma()
            idi = DirectCast(cbIdiomas.SelectedItem, Idioma)
            Try
                Current.Idioma = idi
                Me.Close()
                My.Application.ReloadLanguage()
            Catch ex As Exception
                My.Application.HandlerException(New LanguageFileNotFoundException())
            End Try
        Else
            MyBase.SetErrorUI(cbIdiomas, New ItemSelectRequiredException())
        End If
    End Sub


End Class